package cn.lili.modules.member.mapper;

import cn.lili.modules.member.entity.dos.Partner;
import cn.lili.modules.member.entity.vo.PartnerVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * create by yudan on 2022/2/18
 */
public interface PartnerMapper extends BaseMapper<Partner> {

    @Select("SELECT * from ("
            + "select count(e.id) quantity,p.partner_state,p.partner_type,p.create_time,"
            + "p.begin_time,p.end_time,m.username,m.id,m.face,m.region,m.promotion_img,m.promotion_code,m.mobile from li_member m "
            + " left join li_extension e on e.extension = m.promotion_code"
            + " left join li_partner p on p.member_id = m.id "
            + " ${ew.customSqlSegment} ) a"
            + " ORDER BY a.quantity DESC ,a.partner_type DESC ")
    IPage<PartnerVO> getPartnerPage(IPage<Partner> page, @Param(Constants.WRAPPER) Wrapper<Partner> queryWrapper);

    //根据会员id修改状态
    @Update("UPDATE li_partner set delete_flag = 1, partner_state = 1 where member_id = #{memberId}")
    boolean updateByMemberId(String memberId);
}
